﻿using System;
using System.IO;
using System.Text;
using System.Web.Mvc;
using InfoTech.LanTranh.MucVu.Service;

namespace GiaoXuLanTranh_MucVu.Areas.AdminCP.Controllers
{
    [Authorize]
    public class ReportsController : Controller
    {
        public FileResult RuaToi(string id)
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.RuaToi(id));
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-excel", "RuaToi.xls");
        }

        public ActionResult RuocLe(string id)
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.RuocLe(id));
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-excel", "RuocLe.xls");
        }

        public ActionResult ThemSuc(string id)
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.ThemSuc(id));
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-excel", "ThemSuc.xls");
        }

        public ActionResult ChuaRuaToi()
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.ChuaRuaToi());
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-excel", "ChuaRuaToi.xls");
        }

        public ActionResult ChuaRuocLe()
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.ChuaRuocLe());
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-excel", "ChuaRuocLe.xls");
        }

        public ActionResult ChuaThemSuc()
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.ChuaThemSuc());
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-excel", "ChuaThemSuc.xls");
        }

        public ActionResult XucDau(string id)
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.XucDau(id));
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-excel", "XucDau.xls");
        }

        public ActionResult TaThe(string id)
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.TaThe(id));
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-excel", "TaThe.xls");
        }

        public ActionResult TanHien(string id)
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.TanHien(id));
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-excel", "TanHien.xls");
        }

        public ActionResult GiaoDan()
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.GiaoDan());
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-excel", "GiaoDan.xls");
        }

        public ActionResult HonPhoi(string id)
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.HonNhan(id));
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-excel", "HonNhan.xls");
        }

        public ActionResult HoGiaDinh()
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.HoGiaDinh());
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-excel", "HoGiaDinh.xls");
        }

        public ActionResult Reports_GiaoHo(string id)
        {
            string result = ReportService.ThongTinHoGiaoHo(id, true);
            return Content(result);
        }

        public ActionResult Reports_GiaoHo1(string id)
        {
            string result = ReportService.ThongTinHoGiaoHo(id, false);
            return Content(result);
        }

        public ActionResult Reports_HoGiaDinh(string id)
        {
            string result = ReportService.ThongTinHoGiaDinh(id, true);
            return Content(result);
        }

        public ActionResult Reports_HoGiaDinh1(string id)
        {
            return Content(ReportService.ThongTinHoGiaDinh(id, false));
        }

        public ActionResult ThongTinGiaoDan(string id)
        {
            return Content(ReportService.ThongTinGiaoDan(id));
        }

        public ActionResult ThongTinHoGiaDinh(string id)
        {
            return Content(ReportService.ThongTinHoGiaDinh(id, true));
        }

        public ActionResult Reports_HoGiaDinh2(string id)
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.ThongTinHoGiaDinh(id));
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-word", "HoGiaDinh.doc");
        }

        public ActionResult Reports_GiaoHo2(string id)
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.ThongTinHoGiaoHo(id));
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-word", "GiaoHo.doc");
        }

        public ActionResult Reports_GiaoHo3(string id)
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(ReportService.ThongTinHoGiaoHo2(id));
                writer.Flush();
            }
            return File(stream.ToArray(), "application/vnd.ms-word", "GiaoHo.doc");
        }
    }
}
